<template>
  <div>
    <Table
      class="monitor-table"
      :columns="colData"
      :data="showTableData"
      :height="tableHeight"
      highlight-row
      @on-current-change="handleRowChange"
      @on-row-dblclick="handleTableClick"
    ></Table>
    <Modal
      class="table-detail-xxx"
      class-name="vertical-center-modal"
      v-model="isShowModal"
      width="1080"
      footer-hide
    >
      <p slot="header" style="height:50px;line-height:50px;font-size:36px;">
        <span>{{eventDetailTitle}}</span>
      </p>
      <div style="height: 100%;">
        <img :src="eventDetailData.http_url_image" width="100%" height="100%"/>
      </div>
    </Modal>
  </div>
</template>

<script>
export default {
  name: "eventsTable",
  props: {
    tableData: {
      type: Array
    },
    tableHeight: {
      type: String,
      default: '300'
    }
  },
  data() {
    return {
      // 弹出 对话框 显示事件详情
      eventDetailData: {},
      isShowModal: false, // 是否显示对话框
      colData: [
        { title: "发生时间", key: "datetime", width: "200", align: "center" },
        { title: "事件名称", key: "action", width: "auto", align: "center" },
        { title: "事件状态", key: "status", width: "100", align: "center" },
        {
          title: "事件详情",
          key: "detail",
          width: "100",
          align: "center",
          render: (h, params) => {
            return h("Button",
              {
                props: {
                  type: "success",
                  size: "small"
                },
                style: {
                  marginRight: "5px"
                },
                on: {
                  click: () => {
                    this.eventDetailData = params.row
                    this.isShowModal = true
                  }
                }
              },
              "查看详情",
            );
          }
        }
      ]
    };
  },
  computed: {
    showTableData() {
      return this.tableData.map(ele => {
        ele.cellClassName = {
          status: ele.status === "合规" ? "demo-table-info-cell-legal" : "demo-table-info-cell-illegal",
          action: ele.status === "合规" ? "demo-table-info-cell-legal" : "demo-table-info-cell-illegal"
        }
        return ele
      });
    },
    eventDetailTitle() {
      return this.eventDetailData.action + ' - ' + this.eventDetailData.cause + ' - ' + this.eventDetailData.datetime
    }
  },
  methods: {
    handleTableClick(row, index) {
      this.eventDetailData = row
      this.isShowModal = true
    },
    handleRowChange(currentRow, oldCurrentRow){
      // console.log('单击行：', currentRow, oldCurrentRow)
    }
  }
};
</script>

<style lang="less">
@table-background-color: #0a4271;

.monitor-table .ivu-table {
  color: #fff;
  font-size: 16px;
  background-color: #01237c;
  overflow-x: hidden;
  overflow-y: hidden;
}
// 表格字体
.monitor-table .ivu-table td {
  font-size: 16px ;
}
// 表格头的字体
.monitor-table .ivu-table th {
  background-color: @table-background-color;
  font-size: 16px;
  height: 30px;
}
.monitor-table .ivu-table-wrapper {
  border: 1px solid @table-background-color;
}
.monitor-table .ivu-table:after {
  background-color: @table-background-color;
}
.monitor-table .ivu-table td,.ivu-table th {
  border-bottom: 1px solid @table-background-color;
}
// 合规
.monitor-table .ivu-table .demo-table-info-cell-legal {
  color: #13c2c2;
  font-weight: bold;
}
// 违规
.monitor-table .ivu-table .demo-table-info-cell-illegal {
  color: #ffec3d;
  font-weight: bold;
}
.monitor-table .ivu-table-row-highlight td {
  background-color: #36cfc9 !important;
}
.demo-table-row-selected {
  background-color: #ffec3d;
}
.table-detail-xxx .ivu-icon-ios-close {
  font-size: 61px !important;
}
</style>
